package com.mashiro.system.controller;

import com.mashiro.common.annotation.Log;
import com.mashiro.common.core.controller.BaseController;
import com.mashiro.common.core.domain.AjaxResult;
import com.mashiro.common.core.page.TableDataInfo;
import com.mashiro.common.enums.BusinessType;
import com.mashiro.common.utils.poi.ExcelUtil;
import com.mashiro.system.domain.MoeAcceptance;
import com.mashiro.system.service.IMoeAcceptanceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 验收管理Controller
 *
 * @author mashiro
 * @date 2023-04-14
 */
@RestController
@RequestMapping("/system/acceptance")
public class MoeAcceptanceController extends BaseController {
    @Resource
    private IMoeAcceptanceService moeAcceptanceService;

    /**
     * 查询验收管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:acceptance:list')")
    @GetMapping("/list")
    public TableDataInfo list(MoeAcceptance moeAcceptance) {
        startPage();
        List<MoeAcceptance> list = moeAcceptanceService.selectMoeAcceptanceList(moeAcceptance);
        return getDataTable(list);
    }

    /**
     * 导出验收管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:acceptance:export')")
    @Log(title = "验收管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MoeAcceptance moeAcceptance) {
        List<MoeAcceptance> list = moeAcceptanceService.selectMoeAcceptanceList(moeAcceptance);
        ExcelUtil<MoeAcceptance> util = new ExcelUtil<MoeAcceptance>(MoeAcceptance.class);
        util.exportExcel(response, list, "验收管理数据");
    }

    /**
     * 获取验收管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:acceptance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(moeAcceptanceService.selectMoeAcceptanceById(id));
    }

    /**
     * 新增验收管理
     */
    @PreAuthorize("@ss.hasPermi('system:acceptance:add')")
    @Log(title = "验收管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MoeAcceptance moeAcceptance) {
        return toAjax(moeAcceptanceService.insertMoeAcceptance(moeAcceptance));
    }

    /**
     * 修改验收管理
     */
    @PreAuthorize("@ss.hasAnyPermi('system:acceptance:edit,system:acceptance:accept,system:acceptance:reject')")
    @Log(title = "验收管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MoeAcceptance moeAcceptance) {
        return toAjax(moeAcceptanceService.updateMoeAcceptance(moeAcceptance));
    }

    /**
     * 删除验收管理
     */
    @PreAuthorize("@ss.hasPermi('system:acceptance:remove')")
    @Log(title = "验收管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(moeAcceptanceService.deleteMoeAcceptanceByIds(ids));
    }

    /**
     * 获取验收详情
     */
    @PreAuthorize("@ss.hasPermi('system:acceptance:query')")
    @GetMapping("/info/{id}")
    public AjaxResult getAcceptanceInfo(@PathVariable Long id) {
        return success(moeAcceptanceService.getAcceptanceInfo(id));
    }
}
